# demo03_encap.py
# 创建银行账户类，包含的属性有账号、户名、余额，都不能被外部访问
class BankAccount:
    # 通过构造方法对象中添加属性
    def __init__(self, number, holder, balance, phone):
        # 设置为私有属性，只能在类的内部访问
        # 以__开头的属性就是私有属性
        self.__account_number = number
        self.__account_holder = holder
        self.__balance = balance
        self.__phone = phone
    def get_phone(self):
        return self.__phone
    def set_phone(self, phone):
        self.__phone = phone

    # 添加方法，可以访问到账户
    def get_account_number(self):
        return self.__account_number
    def get_balance(self): # 访问余额
        return self.__balance
    # 存钱/取钱方法，私有方法，不能被外部调用
    def __add_amount(self, amount):
        self.__balance += amount
    # 存款方法
    def cunkuan(self, num):
        # 判断要存的值是否为正数
        if num > 0:
            self.__add_amount(num)
            print('存款成功，您当前的余额：', self.__balance)
        else:
            print('存款失败，不能是负数')
    # 取款方法
    def qukuan(self, num):
        # 余额超过取款金额，不能是负数
        if self.__balance >= num and num > 0:
            self.__add_amount(-num)
            print(f'取款成功！本次取款金额{num},余额{self.__balance}')
        elif self.__balance < num:
            print('余额不足')
        else:
            print('取款金额必须大于0')

if __name__ == '__main__':
    a1 = BankAccount('6222001', '小明', 1000, '18812345678')
    # a1.cunkuan(5000)
    a1.qukuan(-500)
    # a1.set_phone('19988889999')
    # print(a1.get_phone())
    # print(a1.get_account_number(), a1.get_balance())


    # a2 = BankAccount('6222002', '小红', 500)